//
//  TransferManagerViewController.m
//  PigMarket
//
//  Created by mac on 2019/5/9.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "TransferManagerViewController.h"
#import "XXPageTabView.h"
#import "TransferPigListViewController.h"
#import "TransferRecordViewController.h"


@interface TransferManagerViewController ()<XXPageTabViewDelegate>
/**
 bgImg
 */
@property (nonatomic , strong) UIImageView *bgImg;
/**
 pageTableView
 */
@property (nonatomic , strong) XXPageTabView *pageTabView;
/**
 被转让的猪
 */
@property (nonatomic , strong) TransferRecordViewController *recordVC;
/**
 转让记录
 */
@property (nonatomic , strong) TransferPigListViewController *pigListVC;

@end

@implementation TransferManagerViewController

#pragma mark - view life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"转让管理";
    [self initNav];
    [self setUpView];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

-(void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

#pragma mark - init method
- (void)initNav {
   // [[NavigationBarManager sharedInstance] setupNavigationBarClear:self.navigationController];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"adopt_adoptdetail_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backTapped)];
}
- (void)setUpView {
    [self initView];
    [self initLayout];
    [self initAction];
    [self initData];
}
- (void)initView {
    [self addChildViewController:self.pigListVC];
    [self addChildViewController:self.recordVC];
    
    [self.view addSubview:self.bgImg];
    [self.bgImg bringSubviewToFront:self.view];
    [self.view addSubview:self.pageTabView];
}

- (void) initLayout {
    [self.bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(-TopBarHeight);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(197);
    }];
    [self.pageTabView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}

- (void) initAction {
    
}

- (void)initData {
    
}

#pragma mark - delegate
- (void)scrollToLast:(id)sender {
    [self.pageTabView setSelectedTabIndexWithAnimation:self.pageTabView.selectedTabIndex-1];
}

- (void)scrollToNext:(id)sender {
    [self.pageTabView setSelectedTabIndexWithAnimation:self.pageTabView.selectedTabIndex+1];
}
#pragma mark - target action
- (void)backTapped {
    //如果是从转让结果页面跳进来的   需移除对应控制器   返回到我得领养页面
//    [self.rtNavigationController removeViewControllerWithName:@"TransferTypeViewController"];
//    [self.rtNavigationController removeViewControllerWithName:@"TransferInfoViewController"];
//    [self.rtNavigationController removeViewControllerWithName:@"InputTransferInfoViewController"];
//    [self.rtNavigationController removeViewControllerWithName:@"TransferResultViewController"];

    [self.navigationController popViewControllerAnimated:YES];
}
- (void)transferManagerTapped {
    
}
#pragma mark - private method

#pragma mark - getter and setter
- (UIImageView *)bgImg {
    if (!_bgImg) {
        _bgImg = [[UIImageView alloc] init];
        _bgImg.image = [UIImage imageNamed:@"adopted_transfermanager"];
    }
    return _bgImg;
}
- (XXPageTabView *)pageTabView {
    if (!_pageTabView) {
        _pageTabView = [[XXPageTabView alloc] initWithChildControllers:self.childViewControllers childTitles:@[@"被转让的猪",@"转让记录"]];
        _pageTabView.delegate = self;
        _pageTabView.indicatorStyle = XXPageTabIndicatorStyleFollowText;//跟随文本变化长度
        _pageTabView.titleStyle = XXPageTabTitleStyleGradient;//渐变
        _pageTabView.selectedTabIndex = 0;
        _pageTabView.separatorColor = [UIColor clearColor];
        _pageTabView.tabItemFont = [UIFont systemFontOfSize:16];
        _pageTabView.indicatorHeight = 0;
        _pageTabView.unSelectedColor = [UIColor colorWithHexString:@"#FFFFFF"];
        _pageTabView.selectedColor = [UIColor colorWithHexString:@"#FFFFFF"];
        _pageTabView.tabBackgroundColor = [UIColor clearColor];
        _pageTabView.bodyBackgroundColor = [UIColor clearColor];
    }
    return _pageTabView;
}
- (TransferPigListViewController *)pigListVC {
    if (!_pigListVC) {
        _pigListVC = [[TransferPigListViewController alloc] init];
    }
    return _pigListVC;
}
- (TransferRecordViewController *)recordVC {
    if (!_recordVC) {
        _recordVC = [[TransferRecordViewController alloc] init];
    }
    return _recordVC;
}
@end
